const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');

const webpack = require('webpack')

const definePlugin = new webpack.DefinePlugin({
    process: JSON.stringify({
        resourceUrl: 'http://localhost:20048/'
    })
})
const htmlPlugin = new HtmlWebpackPlugin({
    template: path.join('index.html')
})
const cleanPlugin = new CleanWebpackPlugin()
const terserPlugin = new TerserPlugin({
    parallel: 4,
    terserOptions: {
        parse: {
            ecma: 8,
        },
        compress: {
            ecma: 5,
            warnings: false,
            comparisons: false,
            inline: 2,
        },
        mangle: {
            safari10: true,
        },
        output: {
            ecma: 5,
            comments: false,
            ascii_only: true,
        },
    },
})


module.exports = {
    entry: './src/main.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'public/bundle.js'
    },
    devtool: 'inline-cheap-module-source-map',
    optimization: {
        minimizer: [
            terserPlugin,
        ]
    },
    plugins: [
        definePlugin, htmlPlugin, cleanPlugin,
    ],
};